package com.youyi.yyviewsdklibrary.Dialog.util;

import android.content.Context;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.youyi.yyviewsdklibrary.Dialog.core.ImageViewerPopupView;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.XPopupImageLoader;
import com.youyi.yyviewsdklibrary.Dialog.photoview.OnMatrixChangedListener;
import com.youyi.yyviewsdklibrary.Dialog.photoview.PhotoView;
import java.io.File;

public class SmartGlideImageLoader implements XPopupImageLoader {
    private int errImg;
    private boolean mBigImage;

    public SmartGlideImageLoader() {
    }

    public SmartGlideImageLoader(int i) {
        this.errImg = i;
    }

    public SmartGlideImageLoader(boolean z, int i) {
        this(i);
        this.mBigImage = z;
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(7:0|(1:2)(1:3)|4|(2:10|(3:12|13|14)(1:15))|16|17|20) */
    /* JADX WARNING: Code restructure failed: missing block: B:18:0x008f, code lost:
        r5 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:19:0x0090, code lost:
        r5.printStackTrace();
        com.bumptech.glide.Glide.with(r7).downloadOnly().load(r6).into(new com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass2(r4));
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x004e */
    @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.XPopupImageLoader
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public View loadImage(int r5, Object r6, ImageViewerPopupView r7, PhotoView r8, final ProgressBar r9) {
        /*
        // Method dump skipped, instructions count: 168
        */
        throw new UnsupportedOperationException("Method not decompiled: com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.loadImage(int, java.lang.Object, com.youyi.yyviewsdklibrary.Dialog.core.ImageViewerPopupView, com.youyi.yyviewsdklibrary.Dialog.photoview.PhotoView, android.widget.ProgressBar):android.view.View");
    }

    private SubsamplingScaleImageView buildBigImageView(final ImageViewerPopupView imageViewerPopupView, ProgressBar progressBar, final int i) {
        SubsamplingScaleImageView subsamplingScaleImageView = new SubsamplingScaleImageView(imageViewerPopupView.getContext());
        subsamplingScaleImageView.setOnStateChangedListener(new SubsamplingScaleImageView.DefaultOnStateChangedListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass3 */

            @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnStateChangedListener, com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.DefaultOnStateChangedListener
            public void onCenterChanged(PointF pointF, int i) {
                super.onCenterChanged(pointF, i);
            }
        });
        subsamplingScaleImageView.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass4 */

            public void onClick(View view) {
                imageViewerPopupView.dismiss();
            }
        });
        if (imageViewerPopupView.longPressListener != null) {
            subsamplingScaleImageView.setOnLongClickListener(new View.OnLongClickListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass5 */

                public boolean onLongClick(View view) {
                    imageViewerPopupView.longPressListener.onLongPressed(imageViewerPopupView, i);
                    return false;
                }
            });
        }
        return subsamplingScaleImageView;
    }

    private PhotoView buildPhotoView(final ImageViewerPopupView imageViewerPopupView, final PhotoView photoView, final int i) {
        final PhotoView photoView2 = new PhotoView(imageViewerPopupView.getContext());
        photoView2.setZoomable(false);
        photoView2.setOnMatrixChangeListener(new OnMatrixChangedListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass6 */

            @Override // com.youyi.yyviewsdklibrary.Dialog.photoview.OnMatrixChangedListener
            public void onMatrixChanged(RectF rectF) {
                if (photoView != null) {
                    Matrix matrix = new Matrix();
                    photoView2.getSuppMatrix(matrix);
                    photoView.setSuppMatrix(matrix);
                }
            }
        });
        photoView2.setOnClickListener(new View.OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass7 */

            public void onClick(View view) {
                imageViewerPopupView.dismiss();
            }
        });
        if (imageViewerPopupView.longPressListener != null) {
            photoView2.setOnLongClickListener(new View.OnLongClickListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass8 */

                public boolean onLongClick(View view) {
                    imageViewerPopupView.longPressListener.onLongPressed(imageViewerPopupView, i);
                    return false;
                }
            });
        }
        return photoView2;
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.XPopupImageLoader
    public void loadSnapshot(Object obj, final PhotoView photoView, ImageView imageView) {
        if (this.mBigImage) {
            if (!(imageView == null || imageView.getDrawable() == null)) {
                try {
                    photoView.setImageDrawable(imageView.getDrawable().getConstantState().newDrawable());
                } catch (Exception unused) {
                }
            }
            Glide.with(photoView).downloadOnly().load(obj).into(new ImageDownloadTarget() {
                /* class com.youyi.yyviewsdklibrary.Dialog.util.SmartGlideImageLoader.AnonymousClass9 */

                @Override // com.youyi.yyviewsdklibrary.Dialog.util.ImageDownloadTarget, com.bumptech.glide.request.target.Target
                public void onLoadFailed(Drawable drawable) {
                    super.onLoadFailed(drawable);
                }

                @Override // com.youyi.yyviewsdklibrary.Dialog.util.ImageDownloadTarget
                public void onResourceReady(File file, Transition<? super File> transition) {
                    super.onResourceReady(file, transition);
                    int rotateDegree = XPopupUtils.getRotateDegree(file.getAbsolutePath());
                    int appWidth = XPopupUtils.getAppWidth(photoView.getContext());
                    int screenHeight = XPopupUtils.getScreenHeight(photoView.getContext());
                    int[] imageSize = XPopupUtils.getImageSize(file);
                    if (imageSize[0] > appWidth || imageSize[1] > screenHeight) {
                        photoView.setImageBitmap(XPopupUtils.rotate(XPopupUtils.getBitmap(file, appWidth, screenHeight), rotateDegree, ((float) imageSize[0]) / 2.0f, ((float) imageSize[1]) / 2.0f));
                        return;
                    }
                    Glide.with(photoView).load(file).apply(new RequestOptions().override(imageSize[0], imageSize[1])).into(photoView);
                }
            });
            return;
        }
        try {
            Glide.with(photoView).load(obj).apply(new RequestOptions().skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).fitCenter()).into(photoView);
        } catch (Exception e) {
            e.printStackTrace();
            Glide.with(photoView).load(obj).into(photoView);
        }
    }

    @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.XPopupImageLoader
    public File getImageFile(Context context, Object obj) {
        try {
            return (File) Glide.with(context).downloadOnly().load(obj).submit().get();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
